//
//  RaiseDetailViewController.m
//  Kjs-iOS
//
//  Created by 江伟 on 16/8/1.
//  Copyright © 2016年 jmhz. All rights reserved.
//

#import "RaiseDetailViewController.h"
#import "RaiseDetailUiView.h"
#import "SelectModeViewController.h"
#import "UploadRaiseInfoViewController.h"
#import "AppDelegate.h"
#import "KJSRequest.h"
#import "UploadRaiseInfoOrgViewController.h"

#define screenW [[UIScreen mainScreen] bounds].size.width //屏幕宽度
#define screenH [[UIScreen mainScreen] bounds].size.height //屏幕高度

#define toolViewH 40 //高度

#define PROVINCE_COMPONENT 0
#define CITY_COMPONENT 1
#define DISTRICT_COMPONENT 2

@interface RaiseDetailViewController ()<UITextFieldDelegate,UIPickerViewDataSource,UIPickerViewDelegate>
@property (nonatomic,strong)  UIScrollView *scrollV;
@property (nonatomic,strong) RaiseDetailUiView *raiseDetailV;
@property (nonatomic,assign) int benefitMode;
@property (nonatomic,assign) int gdIfPledge;

@property (nonatomic,assign) NSInteger needImgNum;
@property (nonatomic,assign) Boolean imgIsEnough;

@property (nonatomic,strong) NSMutableArray *baseInfoImgUrlArray;
@property (nonatomic,strong) NSMutableArray *assetProofArray;
@property (nonatomic,strong) NSMutableArray *creditProofUrlArray;
@property (nonatomic,strong) NSMutableArray *relevantLawUrlArray;
@property (nonatomic,strong) NSMutableArray *otherInfoUrlArray;
@property (nonatomic,strong) NSMutableArray *businessConditionsInfoUrlArray;
@property (nonatomic,strong) NSMutableArray *assetPropertyProofUrlArray;
@property (nonatomic,strong) NSMutableArray *financeReportInfoUrlArray;

@property (nonatomic,strong) NSMutableArray *baseInfoImgIdArray;
@property (nonatomic,strong) NSMutableArray *assetProofIdArray;
@property (nonatomic,strong) NSMutableArray *creditProofIdArray;
@property (nonatomic,strong) NSMutableArray *relevantLawIdArray;
@property (nonatomic,strong) NSMutableArray *otherInfoIdArray;
@property (nonatomic,strong) NSMutableArray *businessConditionsInfoIdArray;
@property (nonatomic,strong) NSMutableArray *assetPropertyProofIdArray;
@property (nonatomic,strong) NSMutableArray *financeReportInfoIdArray;

@property (nonatomic,strong) NSString *provinceStr;
@property (nonatomic,strong) NSString *cityStr;
@property (nonatomic,strong) NSString *districtStr;

@property (nonatomic,strong) NSDictionary *areaDic;
@property (nonatomic,strong) NSArray *provincePickerArray;
@property (nonatomic,strong) NSArray *cityPickerArray;
@property (nonatomic,strong) NSArray *districtPickerArray;
@property (nonatomic,strong) NSString *selectedProvince;
@property (nonatomic,strong) NSArray *cityCodeArray;

@property (nonatomic,strong) UIPickerView *areaPickerView;
@property (nonatomic,strong) UIToolbar *areaToolbar;
@property (nonatomic,strong) UIView *separateView;

@end

@implementation RaiseDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.benefitMode = -1;
    self.needImgNum = -1;
    
    [self.navigationItem setTitle:@"填写融资信息"];
    self.scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screenW, screenH)];
    self.raiseDetailV = [[[NSBundle mainBundle] loadNibNamed:@"RaiseDetailView" owner:self options:nil] firstObject];
    [self.raiseDetailV setFrame:CGRectMake(0, 0, screenW, self.raiseDetailV.frame.size.height)];
    [self.scrollV setBackgroundColor:self.raiseDetailV.backgroundColor];
    self.scrollV.contentSize = self.raiseDetailV.frame.size;
    [self.scrollV addSubview:self.raiseDetailV];
    [self.view addSubview:self.scrollV];
    
    UITapGestureRecognizer *goUploadDetail = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goUploadDetail) ];
    [self.raiseDetailV.infoArrowImageV addGestureRecognizer:goUploadDetail];
    
    UITapGestureRecognizer *goSelectMode = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goSelectMode) ];
    [self.raiseDetailV.modeArrowImageV addGestureRecognizer:goSelectMode];
    
    [self.raiseDetailV.gdIfPledgeSwich addTarget:self action:@selector(changeSwich) forControlEvents:UIControlEventValueChanged];
    self.gdIfPledge = 0;

    [self.raiseDetailV.submit addTarget:self action:@selector(submitItemInfo) forControlEvents:UIControlEventTouchUpInside];
   
    [self.raiseDetailV.selectAddrBtn addTarget:self action:@selector(popAreaPickerView) forControlEvents:UIControlEventTouchUpInside];
    //添加省市区选择器
    [self setPickerData];
    self.areaPickerView = [[UIPickerView alloc] init];
    self.areaPickerView.delegate = self;
    self.areaPickerView.dataSource = self;
    self.areaPickerView.backgroundColor = [UIColor whiteColor];
    self.areaPickerView.frame = CGRectMake(0, screenH, screenW, 100);
    self.areaPickerView.tag = 2;
    
    self.areaToolbar = [[UIToolbar alloc] init];
    self.areaToolbar.frame = CGRectMake(0, self.areaPickerView.frame.origin.y - toolViewH, screenW, toolViewH);
    UIBarButtonItem *spaceAreaPickerButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *doneAreaPickerButton = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(inAreaPickerView)];
    self.areaToolbar.items = @[spaceAreaPickerButton,doneAreaPickerButton];
    
    self.separateView = [[UIView alloc] init];
    [self.separateView setBackgroundColor:[UIColor colorWithRed:208/255.0f green:208/255.0f blue:208/255.0f alpha:1]];
    self.separateView.frame = CGRectMake(0, self.areaToolbar.frame.origin.y + toolViewH - 1, screenW, 1);
    [self.view addSubview:self.areaToolbar];
    [self.view addSubview:self.areaPickerView];
    [self.view addSubview:self.separateView];
    
    self.raiseDetailV.gdAnnualizedBenefitRateTF.delegate = self;
    self.provinceStr = @"";
    self.cityStr = @"";
    self.districtStr = @"";
    //点击空白处，收回键盘
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(endEdit)];
    self.view.userInteractionEnabled = YES;
    [self.view addGestureRecognizer:tap];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (self.needImgNum <= 0) {
        self.raiseDetailV.imgNumLab.text = @"未上传需求材料图片";
    }else{
        self.raiseDetailV.imgNumLab.text = [NSString stringWithFormat:@"已上传必需材料%ld张",self.needImgNum];
    }
    NSLog(@"imgIsEnough=%i",self.imgIsEnough);
    NSLog(@"getDocListStr=%@",[self getDocListStr]);
}
-(void)displayViewController:(UIViewController *)viewController
{
    [super displayViewController:viewController];
    [self.view endEditing:YES];
}
#pragma mark - initConfigeration
-(void)endEdit
{
    [self.view endEditing:YES];
}
-(void)setPickerData{
    
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath = [bundle pathForResource:@"area" ofType:@"plist"];
    self.areaDic = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
    
    NSArray *components = [self.areaDic allKeys];
    NSArray *sortedArray = [components sortedArrayUsingComparator: ^(id obj1, id obj2) {
        
        if ([obj1 integerValue] > [obj2 integerValue]) {
            return (NSComparisonResult)NSOrderedDescending;
        }
        
        if ([obj1 integerValue] < [obj2 integerValue]) {
            return (NSComparisonResult)NSOrderedAscending;
        }
        return (NSComparisonResult)NSOrderedSame;
    }];
    
    NSMutableArray *provinceTmp = [[NSMutableArray alloc] init];
    for (int i=0; i<[sortedArray count]; i++) {
        NSString *index = [sortedArray objectAtIndex:i];
        NSArray *tmp = [[self.areaDic objectForKey: index] allKeys];
        [provinceTmp addObject: [tmp objectAtIndex:0]];
    }
    
    self.provincePickerArray = [[NSArray alloc] initWithArray: provinceTmp];
    
    NSString *index = [sortedArray objectAtIndex:0];
    //默认选中省
    NSString *selected = [self.provincePickerArray objectAtIndex:0];
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary: [[self.areaDic objectForKey:index]objectForKey:selected]];
    
    NSArray *cityArray = [dic allKeys];
    NSDictionary *cityDic = [NSDictionary dictionaryWithDictionary: [dic objectForKey: [cityArray objectAtIndex:0]]];
    self.cityPickerArray = [[NSArray alloc] initWithArray: [cityDic allKeys]];
    //默认选中市
    NSString *selectedCity = [self.cityPickerArray objectAtIndex: 0];
    self.districtPickerArray = [[NSArray alloc] initWithArray: [cityDic objectForKey: selectedCity]];
}
-(NSString *)getDocListStr
{
    NSMutableArray *docIdArray = [NSMutableArray array];
    [docIdArray addObjectsFromArray:self.baseInfoImgIdArray];
    [docIdArray addObjectsFromArray:self.assetProofIdArray];
    [docIdArray addObjectsFromArray:self.creditProofIdArray];
    [docIdArray addObjectsFromArray:self.relevantLawIdArray];
    [docIdArray addObjectsFromArray:self.otherInfoIdArray];
    [docIdArray addObjectsFromArray:self.businessConditionsInfoIdArray];
    [docIdArray addObjectsFromArray:self.assetPropertyProofIdArray];
    [docIdArray addObjectsFromArray:self.financeReportInfoIdArray];
    NSLog(@"docIdArray=%@",docIdArray);
    NSMutableArray *idDic = [NSMutableArray array];
    for (int i = 0; i < [docIdArray count]; i++) {
        NSDictionary *dic = [NSDictionary dictionaryWithObject:docIdArray[i] forKey:@"kjsItemInfoDocumentId"];
        [idDic addObject:dic];
    }
    if ([idDic count]>0) {
        NSLog(@"idDic=%@",idDic);
        NSDictionary *docListDic = [NSDictionary dictionaryWithObject:idDic forKey:@"userData"];
        NSLog(@"docListDic=%@",docListDic);
        return [self dictionaryToJson:docListDic];
    }else{
        return NULL;
    }
}
- (NSString*)dictionaryToJson:(NSDictionary *)dic

{
    NSError *parseError = nil;
    if ([dic count]!=0){
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
        return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }else{
        return @"";
    }
    
}
-(void)initUrlArray
{
    self.baseInfoImgUrlArray = [NSMutableArray array];
    self.assetProofArray = [NSMutableArray array];
    self.creditProofUrlArray = [NSMutableArray array];
    self.relevantLawUrlArray = [NSMutableArray array];
    self.otherInfoUrlArray = [NSMutableArray array];
    self.businessConditionsInfoUrlArray = [NSMutableArray array];
    self.assetPropertyProofUrlArray = [NSMutableArray array];
    self.financeReportInfoUrlArray = [NSMutableArray array];
}
-(void)initIdArray
{
    self.baseInfoImgIdArray = [NSMutableArray array];
    self.assetProofIdArray = [NSMutableArray array];
    self.creditProofIdArray = [NSMutableArray array];
    self.relevantLawIdArray = [NSMutableArray array];
    self.otherInfoIdArray = [NSMutableArray array];
    self.businessConditionsInfoIdArray = [NSMutableArray array];
    self.assetPropertyProofIdArray = [NSMutableArray array];
    self.financeReportInfoIdArray = [NSMutableArray array];

}
#pragma mark - PickerViewDataSource
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    
    return 3;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    
    NSLog(@"area pickerView");
    if (component == PROVINCE_COMPONENT) {
        return [self.provincePickerArray count];
    }
    else if (component == CITY_COMPONENT) {
        return [self.cityPickerArray count];
    }
    else {
        return [self.districtPickerArray count];
    }
}
#pragma mark - PickerViewDelegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    
    NSLog(@"城市选中");
    if (component == PROVINCE_COMPONENT) {
        self.selectedProvince = [self.provincePickerArray objectAtIndex: row];
        NSDictionary *tmp = [NSDictionary dictionaryWithDictionary: [self.areaDic objectForKey: [NSString stringWithFormat:@"%ld", (long)row]]];
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary: [tmp objectForKey: self.selectedProvince]];
        NSArray *cityArray = [dic allKeys];
        NSArray *sortedArray = [cityArray sortedArrayUsingComparator: ^(id obj1, id obj2) {
            if ([obj1 integerValue] > [obj2 integerValue]) {
                return (NSComparisonResult)NSOrderedDescending;//递减
            }
            if ([obj1 integerValue] < [obj2 integerValue]) {
                return (NSComparisonResult)NSOrderedAscending;//上升
            }
            return (NSComparisonResult)NSOrderedSame;
        }];
                
        NSMutableArray *array = [[NSMutableArray alloc] init];
        for (int i=0; i<[sortedArray count]; i++) {
            NSString *index = [sortedArray objectAtIndex:i];
            NSArray *temp = [[dic objectForKey: index] allKeys];
            [array addObject: [temp objectAtIndex:0]];
        }
        self.cityPickerArray = [[NSArray alloc] initWithArray: array];
        NSDictionary *cityDic = [dic objectForKey: [sortedArray objectAtIndex: 0]];
        self.districtPickerArray = [[NSArray alloc] initWithArray: [cityDic objectForKey: [self.cityPickerArray objectAtIndex: 0]]];
        [pickerView selectRow: 0 inComponent: CITY_COMPONENT animated: YES];
        [pickerView selectRow: 0 inComponent: DISTRICT_COMPONENT animated: YES];
        [pickerView reloadComponent: CITY_COMPONENT];
        [pickerView reloadComponent: DISTRICT_COMPONENT];
        
    }else if (component == CITY_COMPONENT) {
        NSString *provinceIndex = [NSString stringWithFormat: @"%lu", (unsigned long)[self.provincePickerArray indexOfObject: self.selectedProvince]];
        NSDictionary *tmp = [NSDictionary dictionaryWithDictionary: [self.areaDic objectForKey: provinceIndex]];
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary: [tmp objectForKey: self.selectedProvince]];
        NSArray *dicKeyArray = [dic allKeys];
        NSArray *sortedArray = [dicKeyArray sortedArrayUsingComparator: ^(id obj1, id obj2) {
                    
            if ([obj1 integerValue] > [obj2 integerValue]) {
                return (NSComparisonResult)NSOrderedDescending;
            }
            
            if ([obj1 integerValue] < [obj2 integerValue]) {
                return (NSComparisonResult)NSOrderedAscending;
            }
            return (NSComparisonResult)NSOrderedSame;
        }];
        
        NSDictionary *cityDic = [NSDictionary dictionaryWithDictionary: [dic objectForKey: [sortedArray objectAtIndex: row]]];
        NSArray *cityKeyArray = [cityDic allKeys];
        
        self.districtPickerArray = [[NSArray alloc] initWithArray: [cityDic objectForKey: [cityKeyArray objectAtIndex:0]]];
        [pickerView selectRow: 0 inComponent: DISTRICT_COMPONENT animated: YES];
        [pickerView reloadComponent: DISTRICT_COMPONENT];
    }
    
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (component == PROVINCE_COMPONENT) {
        return [self.provincePickerArray objectAtIndex: row];
    }
    else if (component == CITY_COMPONENT) {
        return [self.cityPickerArray objectAtIndex: row];
    }
    else {
        return [self.districtPickerArray objectAtIndex: row];
    }
}
#pragma mark UITextField
- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSLog(@"触发textfile");
    if (textField == self.raiseDetailV.gdAnnualizedBenefitRateTF) {
        NSScanner      *scanner    = [NSScanner scannerWithString:string];
        NSCharacterSet *numbers;
        NSRange         pointRange = [textField.text rangeOfString:@"."];
        
        if ( (pointRange.length > 0) && (pointRange.location < range.location  || pointRange.location > range.location + range.length) )
        {
            numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
        }
        else
        {
            numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
        }
        
        if ( [textField.text isEqualToString:@""] && [string isEqualToString:@"."] )
        {
            return NO;
        }
        
        short remain = 2; //默认保留2位小数
        
        NSString *tempStr = [textField.text stringByAppendingString:string];
        NSUInteger strlen = [tempStr length];
        if(pointRange.length > 0 && pointRange.location > 0){ //判断输入框内是否含有“.”。
            if([string isEqualToString:@"."]){ //当输入框内已经含有“.”时，如果再输入“.”则被视为无效。
                return NO;
            }
            if(strlen > 0 && (strlen - pointRange.location) > remain+1){ //当输入框内已经含有“.”，当字符串长度减去小数点前面的字符串长度大于需要要保留的小数点位数，则视当次输入无效。
                return NO;
            }
        }
        
        NSRange zeroRange = [textField.text rangeOfString:@"0"];
        if(zeroRange.length == 1 && zeroRange.location == 0){ //判断输入框第一个字符是否为“0”
            if(![string isEqualToString:@"0"] && ![string isEqualToString:@"."] && [textField.text length] == 1){ //当输入框只有一个字符并且字符为“0”时，再输入不为“0”或者“.”的字符时，则将此输入替换输入框的这唯一字符。
                textField.text = string;
                return NO;
            }else{
                if(pointRange.length == 0 && pointRange.location > 0){ //当输入框第一个字符为“0”时，并且没有“.”字符时，如果当此输入的字符为“0”，则视当此输入无效。
                    if([string isEqualToString:@"0"]){
                        return NO;
                    }
                }
            }
        }
        
        NSString *buffer;
        if ( ![scanner scanCharactersFromSet:numbers intoString:&buffer] && ([string length] != 0) )
        {
            return NO;
        }
        
    }
    
    return YES;
}
#pragma mark - custom method
-(void)inAreaPickerView{
    NSLog(@"收回PickerView");
    NSInteger provinceIndex = [self.areaPickerView selectedRowInComponent: PROVINCE_COMPONENT];
    NSInteger cityIndex = [self.areaPickerView selectedRowInComponent: CITY_COMPONENT];
    NSInteger districtIndex = [self.areaPickerView selectedRowInComponent: DISTRICT_COMPONENT];
    NSLog(@"%ld,%ld,%ld",provinceIndex,cityIndex,districtIndex);
    NSString *provinceStr = [self.provincePickerArray objectAtIndex: provinceIndex];
    NSString *cityStr = [self.cityPickerArray objectAtIndex: cityIndex];
    NSString *districtStr = [self.districtPickerArray objectAtIndex:districtIndex];
//    if ([provinceStr isEqualToString: cityStr] && [cityStr isEqualToString: districtStr]) {
//        cityStr = @"";
//        districtStr = @"";
//    }
//    else if ([cityStr isEqualToString: districtStr]) {
//        districtStr = @"";
//    }
    NSString *showMsg = [NSString stringWithFormat: @"%@ %@ %@.", provinceStr, cityStr, districtStr];
    self.provinceStr = provinceStr;
    self.cityStr = cityStr;
    self.districtStr = districtStr;
    NSLog(@"地址 = %@,%@,%@",self.provinceStr,self.cityStr,self.districtStr);

    [self.raiseDetailV.selectAddrBtn setTitle:showMsg forState:UIControlStateNormal];
    
    self.areaPickerView.frame = CGRectMake(0, screenH, screenW, 100);
    self.areaToolbar.frame = CGRectMake(0, self.areaPickerView.frame.origin.y - toolViewH, screenW, toolViewH);
    self.separateView.frame = CGRectMake(0, self.areaToolbar.frame.origin.y + toolViewH - 1, screenW, 1);

}
-(void)popAreaPickerView
{
    NSLog(@"弹出pickerView");
    self.areaPickerView.frame = CGRectMake(0,(screenH - 150 - toolViewH)/2, screenW, 150);
    self.areaToolbar.frame = CGRectMake(0, self.areaPickerView.frame.origin.y - toolViewH, screenW, toolViewH);
    self.separateView.frame = CGRectMake(0, self.areaToolbar.frame.origin.y + toolViewH - 1, screenW, 1);
}
-(void)submitItemInfo
{
    [self.view endEditing:YES];
    if ([self.raiseDetailV.nameTF.text isEqualToString:@""]) {
        [GUATool showDialog:@"请输入您的姓名" message:nil waitingTime:1.5];
        [self.raiseDetailV.nameTF becomeFirstResponder];
        
    }else if ([self.raiseDetailV.phoneTF.text isEqualToString:@""]){
        [GUATool showDialog:@"请输入您的联系电话" message:nil waitingTime:1.5];
        [self.raiseDetailV.phoneTF becomeFirstResponder];
        
    }else if ([self.raiseDetailV.emailTF.text isEqualToString:@""]){
        [self.raiseDetailV.emailTF becomeFirstResponder];
        [GUATool showDialog:@"请输入您的电子邮箱" message:nil waitingTime:1.5];
        
    }else if ([self.provinceStr isEqualToString:@""]|[self.cityStr isEqualToString:@""]|[self.districtStr isEqualToString:@""]){
        [GUATool showDialog:@"请输入您所在的地址" message:nil waitingTime:1.5];
        NSLog(@"请输入您所在的地址 = %@,%@,%@",self.provinceStr,self.cityStr,self.districtStr);

        [self.scrollV setContentOffset:CGPointMake(0,self.raiseDetailV.selectAddrBtn.frame.origin.y) animated:YES];
        
    }else if ([self.raiseDetailV.itemNameTF.text isEqualToString:@""]){
        [GUATool showDialog:@"请拟定融资项目的标题" message:nil waitingTime:1.5];
        [self.raiseDetailV.itemNameTF becomeFirstResponder];
        
    }else if ([self.raiseDetailV.gdFinancingRequiredTF.text isEqualToString:@""]){
        [self.raiseDetailV.gdFinancingRequiredTF becomeFirstResponder];
        [GUATool showDialog:@"请说明您的借款用途" message:nil waitingTime:1.5];
        
    }else if ([self.raiseDetailV.gdSrcOfRepaymentTF.text isEqualToString:@""]){
        [self.raiseDetailV.gdSrcOfRepaymentTF becomeFirstResponder];
        [GUATool showDialog:@"请说明您的还款来源" message:nil waitingTime:1.5];
        
    }else if (self.imgIsEnough == false){
        [GUATool showDialog:@"请上传必需材料" message:nil waitingTime:1.5];
        
    }else if ([self.raiseDetailV.targetMoneyTF.text isEqualToString:@""]){
        [self.raiseDetailV.targetMoneyTF becomeFirstResponder];
        [GUATool showDialog:@"请输入您需要的融资金额" message:nil waitingTime:1.5];
        
    }else if ([self.raiseDetailV.gdAnnualizedBenefitRateTF.text isEqualToString:@""]){
        [self.raiseDetailV.gdAnnualizedBenefitRateTF becomeFirstResponder];
        [GUATool showDialog:@"请给出投资人的预期年化收益率" message:nil waitingTime:1.5];
        
    }else if (self.benefitMode == -1){
        [GUATool showDialog:@"请选择还款方式" message:nil waitingTime:1.5];
    }
    else if (CurentDelegate.account.partyId) {
        NSLog(@"ist=%@",[self getDocListStr]);
        NSLog(@"gdtpye = %d",self.gdItemType);
        [KJSRequest SubmitItemInfoWithItemStatus:1 partyId:CurentDelegate.account.partyId contactName:self.raiseDetailV.nameTF.text contactTel:self.raiseDetailV.phoneTF.text contactEmail:self.raiseDetailV.emailTF.text localProvince:self.provinceStr localCity:self.cityStr localCounty:self.districtStr companyName:@"" teamIntroduction:@"" itemName:self.raiseDetailV.itemNameTF.text gdFinancingRequired:self.raiseDetailV.gdFinancingRequiredTF.text gdSrcOfRepayment:self.raiseDetailV.gdSrcOfRepaymentTF.text gdIfPledge:self.gdIfPledge targetMoney:self.raiseDetailV.targetMoneyTF.text gdAnnualizedBenefitRate:self.raiseDetailV.gdAnnualizedBenefitRateTF.text gdBenefitMode:self.benefitMode itemType:@"1" gdItemType:self.gdItemType docList:[self getDocListStr] ret:^(BasicResult *model) {
            if (model.success) {
                [GUATool showDialog:@"提交成功" message:nil waitingTime:1.5];
                [self dismiss:YES];
            }
        }];
    }else{
        [GUATool showDialog:@"请登录" message:nil waitingTime:1.5];
    }
}
-(void)goUploadDetail
{
    if ([CurentDelegate.account.type isEqualToString:@"p"]){
        UploadRaiseInfoViewController *uploadRaiseInfoVC = [[UIStoryboard storyboardWithName:@"Seconed" bundle:nil] instantiateViewControllerWithIdentifier:@"UploadRaiseInfoViewController"];
        //初始化图片url数组
        uploadRaiseInfoVC.baseInfoImgUrlArray = [NSMutableArray array];
        uploadRaiseInfoVC.assetProofArray = [NSMutableArray array];
        uploadRaiseInfoVC.creditProofUrlArray = [NSMutableArray array];
        uploadRaiseInfoVC.relevantLawUrlArray = [NSMutableArray array];
        uploadRaiseInfoVC.otherInfoUrlArray = [NSMutableArray array];
    
        [uploadRaiseInfoVC.baseInfoImgUrlArray addObjectsFromArray:self.baseInfoImgUrlArray];
        [uploadRaiseInfoVC.assetProofArray addObjectsFromArray:self.assetProofArray];
        [uploadRaiseInfoVC.creditProofUrlArray addObjectsFromArray:self.creditProofUrlArray];
        [uploadRaiseInfoVC.relevantLawUrlArray addObjectsFromArray:self.relevantLawUrlArray];
        [uploadRaiseInfoVC.otherInfoUrlArray addObjectsFromArray:self.otherInfoUrlArray];

        uploadRaiseInfoVC.uploadFinish = ^(NSMutableArray *array1,NSMutableArray *array2,NSMutableArray *array3,NSMutableArray *array4,NSMutableArray *array5,Boolean imgIsEnough){
            [self initUrlArray];
            [self.baseInfoImgUrlArray addObjectsFromArray:array1];
            [self.assetProofArray addObjectsFromArray:array2];
            [self.creditProofUrlArray addObjectsFromArray:array3];
            [self.relevantLawUrlArray addObjectsFromArray:array4];
            [self.otherInfoUrlArray addObjectsFromArray:array5];
            self.needImgNum = [array1 count] + [array2 count] + [array3 count] + [array4 count];
            self.imgIsEnough = imgIsEnough;
        };
        //初始化图片id数组
        uploadRaiseInfoVC.baseInfoImgIdArray = [NSMutableArray array];
        uploadRaiseInfoVC.assetProofIdArray = [NSMutableArray array];
        uploadRaiseInfoVC.creditProofIdArray = [NSMutableArray array];
        uploadRaiseInfoVC.relevantLawIdArray = [NSMutableArray array];
        uploadRaiseInfoVC.otherInfoIdArray = [NSMutableArray array];

        [uploadRaiseInfoVC.baseInfoImgIdArray addObjectsFromArray:self.baseInfoImgIdArray];
        [uploadRaiseInfoVC.assetProofIdArray addObjectsFromArray:self.assetProofIdArray];
        [uploadRaiseInfoVC.creditProofIdArray addObjectsFromArray:self.creditProofIdArray];
        [uploadRaiseInfoVC.relevantLawIdArray addObjectsFromArray:self.relevantLawIdArray];
        [uploadRaiseInfoVC.otherInfoIdArray addObjectsFromArray:self.otherInfoIdArray];

        uploadRaiseInfoVC.uploadImageId = ^(NSMutableArray *array1,NSMutableArray *array2,NSMutableArray *array3,NSMutableArray *array4,NSMutableArray *array5){
            [self initIdArray];
            [self.baseInfoImgIdArray addObjectsFromArray:array1];
            [self.assetProofIdArray addObjectsFromArray:array2];
            [self.creditProofIdArray addObjectsFromArray:array3];
            [self.relevantLawIdArray addObjectsFromArray:array4];
            [self.otherInfoIdArray addObjectsFromArray:array5];
        };
        [self displayViewController:uploadRaiseInfoVC];
    }else if ([CurentDelegate.account.type isEqualToString:@"o"]){
        UploadRaiseInfoOrgViewController *uploadRaiseInfoOrgVC = [[UIStoryboard storyboardWithName:@"Seconed" bundle:nil] instantiateViewControllerWithIdentifier:@"UploadRaiseInfoOrgViewController"];
        
        //初始化图片url数组
        uploadRaiseInfoOrgVC.baseInfoImgUrlArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.businessConditionInfoUrlArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.creditProofUrlArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.assetPropertyProofUrlArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.financeReportInfoUrlArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.relevantLawUrlArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.otherInfoUrlArray = [NSMutableArray array];
        
        [uploadRaiseInfoOrgVC.baseInfoImgUrlArray addObjectsFromArray:self.baseInfoImgUrlArray];
        [uploadRaiseInfoOrgVC.businessConditionInfoUrlArray addObjectsFromArray:self.businessConditionsInfoUrlArray];
        [uploadRaiseInfoOrgVC.creditProofUrlArray addObjectsFromArray:self.creditProofUrlArray];
        [uploadRaiseInfoOrgVC.assetPropertyProofUrlArray addObjectsFromArray:self.assetPropertyProofUrlArray];
        [uploadRaiseInfoOrgVC.financeReportInfoUrlArray addObjectsFromArray:self.financeReportInfoUrlArray];
        [uploadRaiseInfoOrgVC.relevantLawUrlArray addObjectsFromArray:self.relevantLawUrlArray];
        [uploadRaiseInfoOrgVC.otherInfoUrlArray addObjectsFromArray:self.otherInfoUrlArray];
        
        uploadRaiseInfoOrgVC.uploadFinish = ^(NSMutableArray *array1,NSMutableArray *array2,NSMutableArray *array3,NSMutableArray *array4,NSMutableArray *array5,NSMutableArray *array6,NSMutableArray *array7,Boolean imgIsEnough){
            [self initUrlArray];
            [self.baseInfoImgUrlArray addObjectsFromArray:array1];
            [self.businessConditionsInfoUrlArray addObjectsFromArray:array2];
            [self.creditProofUrlArray addObjectsFromArray:array3];
            [self.assetPropertyProofUrlArray addObjectsFromArray:array4];
            [self.financeReportInfoUrlArray addObjectsFromArray:array5];
            [self.relevantLawUrlArray addObjectsFromArray:array6];
            [self.otherInfoUrlArray addObjectsFromArray:array7];
            self.needImgNum = [array1 count] + [array2 count] + [array3 count] + [array4 count] + [array5 count] + [array6 count];
            self.imgIsEnough = imgIsEnough;
        };
        //初始化图片id数组
        uploadRaiseInfoOrgVC.baseInfoImgIdArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.businessConditionInfoIdArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.creditProofIdArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.assetPropertyProofIdArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.financeReportInfoIdArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.relevantLawIdArray = [NSMutableArray array];
        uploadRaiseInfoOrgVC.otherInfoIdArray = [NSMutableArray array];
        
        [uploadRaiseInfoOrgVC.baseInfoImgIdArray addObjectsFromArray:self.baseInfoImgIdArray];
        [uploadRaiseInfoOrgVC.businessConditionInfoIdArray addObjectsFromArray:self.businessConditionsInfoIdArray];
        [uploadRaiseInfoOrgVC.creditProofIdArray addObjectsFromArray:self.creditProofIdArray];
        [uploadRaiseInfoOrgVC.assetPropertyProofIdArray addObjectsFromArray:self.assetPropertyProofIdArray];
        [uploadRaiseInfoOrgVC.financeReportInfoIdArray addObjectsFromArray:self.financeReportInfoIdArray];
        [uploadRaiseInfoOrgVC.relevantLawIdArray addObjectsFromArray:self.relevantLawIdArray];
        [uploadRaiseInfoOrgVC.otherInfoIdArray addObjectsFromArray:self.otherInfoIdArray];

        
        uploadRaiseInfoOrgVC.uploadImageId = ^(NSMutableArray *array1,NSMutableArray *array2,NSMutableArray *array3,NSMutableArray *array4,NSMutableArray *array5,NSMutableArray *array6,NSMutableArray *array7){
            [self initIdArray];
            [self.baseInfoImgIdArray addObjectsFromArray:array1];
            [self.businessConditionsInfoIdArray addObjectsFromArray:array2];
            [self.creditProofIdArray addObjectsFromArray:array3];
            [self.assetPropertyProofIdArray addObjectsFromArray:array4];
            [self.financeReportInfoIdArray addObjectsFromArray:array5];
            [self.relevantLawIdArray addObjectsFromArray:array6];
            [self.otherInfoIdArray addObjectsFromArray:array7];
        };
        
        [self displayViewController:uploadRaiseInfoOrgVC];
    }
    
}
-(void)goSelectMode
{
    SelectModeViewController *selectModeVC = [[UIStoryboard storyboardWithName:@"Seconed" bundle:nil] instantiateViewControllerWithIdentifier:@"SelectModeViewController"];
    selectModeVC.selectFinish = ^(int mode){
        self.benefitMode = mode;
        switch (mode) {
            case Month:
                self.raiseDetailV.gdBenefitModeLab.text = @"按月付息到期还本";
                break;
            case Once:
                self.raiseDetailV.gdBenefitModeLab.text = @"到期一次性还本付息";
            default:
                break;
        }
        NSLog(@"%d",self.benefitMode);
    };
    [self displayViewController:selectModeVC];
}
-(void)changeSwich
{
    if (self.raiseDetailV.gdIfPledgeSwich.isOn == YES) {
        NSLog(@"开关打开");
        self.gdIfPledge = 1;

    }else{
        NSLog(@"开关关闭");
        self.gdIfPledge = 0;
    }
    
}

@end
